package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.RegionBean;
import com.mdx.service.IRegionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 区域
 */
@RestController
@RequestMapping("region")
public class RegionController {
    @Resource
    private IRegionService regionService;

    //查询所有区域信息
    @RequestMapping("/findAllRegion")
    public IPage<RegionBean> findAllRegion(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                           @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        return regionService.findByNameKindAndClassName(pageNO,pageSize,null,null,null);
    }

    //添加
    @RequestMapping("addRegion")
    public String addRegion(RegionBean regionBean){
        regionService.save(regionBean);
        return "ok";
    }

    @RequestMapping("/findByItem")
    public IPage<RegionBean> findByItem(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                           @RequestParam(value = "pageSize", defaultValue = "2") int pageSize,
                                        String regionName,String regionKind,String className) {
        return regionService.findByNameKindAndClassName(pageNO,pageSize,regionName,regionKind,className);
    }
}
